package com.sands.ui.login;

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.TextView;

import com.airbnb.lottie.LottieAnimationView;
import com.blankj.utilcode.util.ActivityUtils;
import com.sands.R;
import com.sands.base.BaseActivity;
import com.sands.ui.Activity_Test;
import com.sands.ui.MainActivity;
import com.sands.utils.Titanic;
import com.sands.utils.TitanicTextView;

import butterknife.BindView;

public class Activity_Splash extends BaseActivity {

    private Titanic titanic;
   @BindView(R.id.tv_go)
    TextView tv_go;

    @Override
    public int getLayoutId() {
        return R.layout.activity__splash;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initview();
        LottieAnimationView animationView = (LottieAnimationView) findViewById(R.id.animation_view);
        animationView.setAnimation("i'm_thirsty!.json");
        animationView.loop(true);
        animationView.playAnimation();

        animationView.addAnimatorUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {

            }
        });


        animationView.addAnimatorListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {

            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });


        TitanicTextView myTitanicTextView = (TitanicTextView) findViewById(R.id.titanic_tv);

        AssetManager mgr=getAssets();//得到AssetManager

        Typeface tf=Typeface.createFromAsset(mgr,"Satisfy-Regular.ttf");//根据路径得到Typeface

        myTitanicTextView.setTypeface(tf);//设置字体
        titanic = new Titanic();
        titanic.start(myTitanicTextView);

        ValueAnimator d =new ValueAnimator();


        CountDownTimer  s  = new CountDownTimer(10000,1000) {
            @Override
            public void onTick(long l) {

                String trim = tv_go.getText().toString().trim();
                int i = Integer.parseInt(trim);
                i-=i;
                tv_go.setText(i+"秒");
            }

            @Override
            public void onFinish() {
                ActivityUtils.startActivity(Activity_Splash.this,MainActivity.class);
            }
        };
    }

    @Override
    protected void _onCreate(Bundle savedInstanceState) {

    }

    private void initview() {
        tv_go.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {

        switch (view.getId())
        {
            case R.id.tv_go:
                ActivityUtils.startActivity(this,Activity_Test.class);
                break;

        }
    }
}

